/**
 * 功能描述 联盟团信息导航条
 */

define(function (require, exports, module) {
	var Form = require("form");
	var Dialog = require("dialog");
	
	var store =require("store");
	var activeUser = store.get("user");	
	
    var instance = {
        initComponent: function (params, widget) {
            var form = new Form({
            	parentNode : ".J-form",
            	model : {
                    id: "form",
                    defaultButton : false,
                    layout: "3_1",
                    items: [{
                    	name : "pkPlanItemGroup",
                    	type : "hidden"
                    },{
                    	name : "version",
                    	type : "hidden",
                		defaultValue : "0"
                    },{
                    	name : "planItem.pkPlanItem",
                    	type : "hidden"
                    },{
                    	name : "planItem.version",
                    	type : "hidden",
                		defaultValue : "0"
                    },{
                    	name : "planItem.alliance",
                    	type : "hidden",
                		defaultValue : true
                    },{
                    	name : "checkInStatus",
                    	type : "hidden",
                		defaultValue : "Initial"
                    },{
                   	 	name : "year",
                   	 	type : "date",
                        label : "年度",
                 	   	mode : "YYYY",
                        readonly : true,
                    },{
                   	 	name : "planItem.destination",
                        type : "select",
                        label : "目的地",
                        url : "api/destination/query",
                        keyField:"pkDestination",
						params:function(){
							return{
								"status" : "Setting",
								fetchProperties:"pkDestination,name",
							}
						},
						valueField:"name",
						validate:["required"],
                    },{
	                   	 name : "planItem.allianceOrg",
	                   	 label : "组团单位",
	                   	 type : "select",
	                   	 url : "api/allianceorg/query",
	                     keyField : "pkAllianceOrg",
                         params : function(){
                        	 return {
                        		 fetchProperties : "pkAllianceOrg,name"
                        	 }
                         },
                    	 valueField : "name",
                    	 validate:["required"],
                    },{
                    	 name : "planItem.startDate",
                    	 type : "date",
                         label : "开始日期",
                 	   	 mode : "YYYY-MM-DD",
                 	   	 events: {
							"change": function(e){
								var form = widget.get("form");
				        		var startDate = form.getValue("planItem.startDate");
				        		var endDate = form.getValue("planItem.endDate");
				        		if(startDate !="" && endDate != "" && startDate > endDate){
				        			Dialog.alert({
				        				tip : "提示",
				        				content : "开始日期不能晚于结束日期！"
				        			})
				        			form.setValue("planItem.startDate", "");
				        		}else{
				        			form.setValue("year",startDate);
				        		}
							}
						 },
						 validate:["required"],
                    },{
                   	 	 name : "planItem.endDate",
	                     type : "date",
	                     label : "结束日期",
	                     mode : "YYYY-MM-DD",
	                     events: {
								"change": function(e){
									var form = widget.get("form");
					        		var startDate = form.getValue("planItem.startDate");
					        		var endDate = form.getValue("planItem.endDate");
					        		if(startDate !="" && endDate != "" && startDate > endDate){
					        			Dialog.alert({
					        				tip : "提示",
					        				content : "开始日期不能晚于结束日期！"
					        			})
					        			form.setValue("planItem.endDate", "");
					        		}
								}
							 },
	                     validate:["required"],
                    },{
                   	 name : "signUpNumber",
                     type : "text",
                     label : "报名人数",
                     defaultValue : "0",
                     readonly : true
                }]
                }
            })
        	widget.set("form", form);
        }
    };
    module.exports = instance;
});
